home *** CD-ROM | disk | FTP | other *** search
/ Symantec Visual Cafe for Java 2.5 / symantec-visual-cafe-2.5-database-dev-edition.iso / Visual Cafe Pro v1.0 / TUTORIAL.BIN / NetString.class (.txt) < prev    next >
Encoding:
Java Class File  |  1997-01-30  |  1.7 KB  |  56 lines

  1. package symantec.itools.db.net;
  2.  
  3. import java.io.DataInputStream;
  4. import java.io.DataOutputStream;
  5. import java.io.IOException;
  6. import symjava.sql.SQLException;
  7.  
  8. public class NetString extends ServerObject {
  9.    String _data;
  10.  
  11.    public NetString(String s) {
  12.       if (s != null) {
  13.          this._data = s;
  14.       } else {
  15.          this._data = new String("");
  16.       }
  17.    }
  18.  
  19.    public NetString() {
  20.       this._data = new String("");
  21.    }
  22.  
  23.    int getType() {
  24.       return 52;
  25.    }
  26.  
  27.    void read(DataInputStream in) throws SQLException, IOException, ErrorException {
  28.       int _length = in.readShort();
  29.       if (_length > 0) {
  30.          byte[] b = new byte[_length];
  31.          in.readFully(b, 0, _length);
  32.          this._data = new String(b, 0);
  33.       } else {
  34.          this._data = new String("");
  35.       }
  36.    }
  37.  
  38.    void write(DataOutputStream out) throws IOException {
  39.       int _length = this._data.length();
  40.       out.writeByte(this.getType());
  41.       out.writeShort(_length);
  42.       if (_length > 0) {
  43.          out.writeBytes(this._data);
  44.       }
  45.  
  46.    }
  47.  
  48.    public String getString() {
  49.       return this._data;
  50.    }
  51.  
  52.    public String toString() {
  53.       return this.getString();
  54.    }
  55. }
  56.